import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routers = new Router({
    base: __dirname,
    routes: [
        //   登录
        {
            path: '/login',
            component: (resolve) => { require(['../pages/home/login'], resolve) }
        },
        //   注册
        {
            path: '/register',
            component: (resolve) => { require(['../pages/home/register'], resolve) }
        },
        // 首页
        {
          path: '/',
          name:'agentHome',
          // component: (resolve) => { require(['../pages/home/home1'], resolve) },
          component: (resolve) => { require(['../pages/home/agentHome'], resolve) },
          meta: {
            requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          }
        },
        // 下级
        {
          path: '/lowerLevel',
          name:'lowerLevel',
          component: (resolve) => { require(['../pages/home/lowerLevel'], resolve) },
          meta: {
            requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          }
        },
        // 会员详情
        {
          path: '/lowerLevel-member',
          name:'lowerLevel-member',
          component: (resolve) => { require(['../pages/home/lowerLevel-member'], resolve) },
          meta: {
            requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          }
        },
        // 代理详情
        {
          path: '/lowerLevel-agent',
          name:'lowerLevel-agent',
          component: (resolve) => { require(['../pages/home/lowerLevel-agent'], resolve) },
          meta: {
            requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          }
        },
        // 新增代理
        {
          path: '/creatNewAgent',
          name:'creatNewAgent',
          component: (resolve) => { require(['../pages/home/creatNewAgent'], resolve) },
          meta: {
            requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          }
        },
        // 报表首页
        {
          path: '/allReports',
          name:'allReports',
          component: (resolve) => { require(['../pages/home/allReports'], resolve) },
          meta: {
            requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          }
        },
        //   个人中心
        {
            path: '/userInfo',
            component: (resolve) => { require(['../pages/home/userInfo'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   推广数据
        {
            path: '/promoteData',
            component: (resolve) => { require(['../pages/home/promoteData'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   我的
        {
            path: '/my',
            component: (resolve) => { require(['../pages/home/my'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   安全中心
        {
            path: '/safeCenter',
            component: (resolve) => { require(['../pages/home/safeCenter'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   修改手机号码
        {
            path: '/changePhone',
            component: (resolve) => { require(['../pages/home/changePhone'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   修改邮箱
        {
            path: '/changeMail',
            component: (resolve) => { require(['../pages/home/changeMail'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   绑定新手机号码
        // {
        //     path: '/bindNewPhone',
        //     component: (resolve) => { require(['../pages/home/bindNewPhone'], resolve) },
        //     meta: {
        //         requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
        //     }
        // },
        //   登录密码设置
        {
            path: '/accountPwdSet',
            component: (resolve) => { require(['../pages/home/accountPwdSet'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        // 支付密码设置
        {
            path: '/payPwdSet',
            component: (resolve) => { require(['../pages/home/payPwdSet'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   取款银行卡设置
        {
            path: '/bankCardSet',
            component: (resolve) => { require(['../pages/home/bankCardSet'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   提现
        {
            path: '/extract',
            component: (resolve) => { require(['../pages/home/extract'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   提现记录
        {
            path: '/extractHistory',
            component: (resolve) => { require(['../pages/home/extractHistory'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   提现记录详情
        {
            path: '/withdrawDetail',
            component: (resolve) => { require(['../pages/home/withdrawDetail'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   虚拟币提现记录详情
        {
            path: '/virtualWithdrawDetail',
            component: (resolve) => { require(['../pages/home/virtualWithdrawDetail'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   虚拟币设置
        {
            path: '/virtualCoinSet',
            component: (resolve) => { require(['../pages/home/virtualCoinSet'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   系统消息
        {
            path: '/notice',
            name: 'notice',
            component: (resolve) => { require(['../pages/home/notice'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   资金概况
        {
            path: '/cashDetail',
            name: 'cashDetail',
            component: (resolve) => { require(['../pages/home/cashDetail'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   优惠概况
        {
            path: '/discountDetail',
            name: 'discountDetail',
            component: (resolve) => { require(['../pages/home/discountDetail'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   会员概况
        {
            path: '/allMemberMore',
            name: 'allMemberMore',
            component: (resolve) => { require(['../pages/home/allMemberMore'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   新注册概况
        {
            path: '/newMemberMore',
            name: 'newMemberMore',
            component: (resolve) => { require(['../pages/home/newMemberMore'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   会员/新注册概况-->会员详情
        {
            path: '/allMemberDetail',
            name: 'allMemberDetail',
            component: (resolve) => { require(['../pages/home/allMemberDetail'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   发放礼金
        {
            path: '/giveCashBonus',
            name: 'giveCashBonus',
            component: (resolve) => { require(['../pages/home/giveCashBonus'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   额度存款
        {
            path: '/limitDeposit',
            name: 'limitDeposit',
            component: (resolve) => { require(['../pages/home/limitDeposit'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   下级代存
        {
            path: '/depositToLow',
            name: 'depositToLow',
            component: (resolve) => { require(['../pages/home/depositToLow'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },
        //   客服iframe页面
        {
            path: '/help',
            name: 'help',
            component: (resolve) => { require(['../pages/home/help'], resolve) },
            meta: {
                requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
            }
        },





      ]
});
routers.beforeEach((to, from, next) => {
    //处理tabbar是否显示
    function changedTabbar(to, store) {
        if (to.path == '/' ||
            to.path == '/agentHome' ||
            to.path == '/lowerLevel' ||
            to.path == '/allReports' ||
            to.path == '/my') {
                if(localStorage.getItem('login_flag') === 'true'){
                    store.dispatch('changeNavigator', {
                        isShow: true
                    });
                }
        }else if (to.path == '/login' || to.path == '/register') {
          store.dispatch('changeNavigator', {
            isShow: false
          });
        } else {
            store.dispatch('changeNavigator', {
                isShow: false
            });
        }
    }
    //处理动画
    function changedPageAnimation(to, store) {
        if (store.state.common.backMark == true) {
            store.dispatch("setPageAnimation", {
                enter: 'page-animated fadeInLeft',
                leave: 'page-animated fadeOutRight'
            });
            store.dispatch("setBackMark", false);
        } else {
            if (
                to.path == '/sponsorship'
                ) {
                store.dispatch("setPageAnimation", {
                    enter: '',
                    leave: ''
                });
            } else {
                store.dispatch("setPageAnimation", {
                    enter: 'page-animated fadeInRight',
                    leave: 'page-animated fadeOutLeft'
                });
            }
        }
    }

    var store = routers.app.$store;
    if (typeof store === 'undefined') {

    } else {
        changedTabbar(to, store);
        changedPageAnimation(to, store);
    }
//		console.log("beforeEach to", to);
//		console.log("beforeEach from", from);
//		console.log("beforeEach next", next);
    if (window.localStorage.getItem('login_flag') == 'true') {
        next();
    } else {
        //这里是未登录
        //再判断哪些页面不需要跳转登录
    	//  页面属于特殊处理
        if (to.path == '/login' || to.path == '/register') {
            // "不需要登录的页面"
            next();
        } else {
            // 需要等路页面
            // next({ path: '/login', query: { toPage: to.path } });
            next({ path: '/login'});
        }
    }
});


export default routers
